//
//  biaoqianCell.m
//  HAODE
//
//  Created by panquanReabam.com on 15/10/21.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "biaoqianCell.h"
#import "UIButton+WebCache.h"



@implementation biaoqianCell{
    UIView *containerView;
  
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
}

#define kYOfImageContainer   136.0

- (void)setComment:(biaoqianmodel *)comment
{
    
    [containerView removeFromSuperview];
    
    _comment = comment;
 

       
    self.title.text = comment.title;
    
    NSString* string = comment.createdAt;
    NSLog(@"-------------%@",string);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss"];
    NSDate *destDate= [dateFormatter dateFromString:string];
    
    NSTimeInterval  timeInterval = [destDate timeIntervalSinceNow];
    timeInterval = -timeInterval;
    
    
    NSString*result;
    long temp = 0;
    
    if (timeInterval < 60) {
        result = [NSString stringWithFormat:@"刚刚"];
    }
    else if((temp = timeInterval/60) <60){
        result = [NSString stringWithFormat:@"%ld分前",temp];
    }
    
    else if((temp = temp/60) <24){
        result = [NSString stringWithFormat:@"%ld小时前",temp];
    }
    
    else if((temp = temp/24) <30){
        result = [NSString stringWithFormat:@"%ld天前",temp];
    }
    
    else if((temp = temp/30) <12){
        result = [NSString stringWithFormat:@"%ld月前",temp];
    }
    else{
        temp = temp/12;
        result = [NSString stringWithFormat:@"%ld年前",temp];
    }

    self.time.text = result;
    
    self.author.text = comment.userName;
    
    [self.imageUrl setImageWithURL:[NSURL URLWithString:comment.headImageUrl] placeholderImage:nil];
    [self.imageUrl.layer setCornerRadius:4.0];
    [self.imageUrl.layer setBorderWidth:0.3];
    [self.imageUrl.layer setMasksToBounds:YES];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0, 0, 0, 0.3 });
    [self.imageUrl.layer setBorderColor:colorref2];//边框颜色
    
    
    if (comment.imagePicSmall.count > 0) {
        CGFloat width = 55;
        CGFloat height = 15;
        CGFloat margin = 5;
        CGFloat startX = 5;
        int count = (int)comment.imagePicSmall.count;
        if (comment.imagePicSmall.count >4) {
            count = 3;
        }
        int row = count / 4 + count % 4 > 0 ? 1: 0;
        containerView = [[UIView alloc] initWithFrame:CGRectMake(self.imageUrl.right+8, self.title.bottom+5, self.frame.size.width - startX, row * (margin + height))];
        [self.contentView addSubview:containerView];
        
        for (int i = 0; i < count; i++)
        {
            UIButton *imageView = [[UIButton alloc] init];
            
            [imageView setTitle:[NSString stringWithFormat:@"%@",comment.imagePicSmall[i]]forState:UIControlStateNormal];
            [imageView  setTitleColor:luseColor forState:UIControlStateNormal];
            imageView.titleLabel.textAlignment=NSTextAlignmentCenter;
            imageView.titleLabel.font=[UIFont systemFontOfSize:10];
            imageView.backgroundColor=[UIColor whiteColor];
            [imageView setTitleColor:luseColor forState:0];
            imageView.layer.borderColor=luseColor.CGColor;
            imageView.layer.borderWidth = 0.35;
            [imageView.layer setCornerRadius:2.0];
            int row = i/4;
            int column = i%4;
            CGFloat x = column * (width + margin);
            CGFloat y = row * (height + margin);
            imageView.frame = CGRectMake(x, y, 55, 15);
            
            [containerView addSubview:imageView];
            
        }
    }

    
}


@end




